'''
Created on October 17, 2010

@author: Behrooz Nobakht
'''
from django.contrib.sites.models import Site


'''
We need the information for the current site on the session

@author: Behrooz Nobakht
'''

CURRENT_SITE_URL_KEY = 'current_site_url'

class CurrentSiteMiddleware:
    
    def process_request(self, request):
        temp = request.session.get(CURRENT_SITE_URL_KEY, None)
        if temp is not None:
            return None
        try:
            site = Site.objects.get_current()
        except:
            return None
        request.session[CURRENT_SITE_URL_KEY] = "http://%s" % site.domain
        return None
